package ch06.d2;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

public class AccountTest {
    @Test
    public void test1() throws ParseException {
//        Account a=new Account("张克文","001","123",10000);
//
//        a.login();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d=sdf.parse("2022-05-12 08:52:00");
        System.out.println(changeDate(d));

    }


    public String changeDate(Date d){
        Date now=new Date();
        long time=now.getTime()-d.getTime();
        if(time<10*60*1000){
            return "刚刚";
        }

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String s=sdf.format(d);
        if(Objects.equals(sdf.format(now), s)){
            SimpleDateFormat sdf2=new SimpleDateFormat("HH:mm");
            return sdf2.format(d);
        }

        if(now.getYear()==d.getYear()){
            SimpleDateFormat sdf2=new SimpleDateFormat("MM-dd");
            return sdf2.format(d);
        }


        return s;
    }

}
